import { propsStatus, eventStatus } from './poolType'

export function createPool(dom, methods) {

  const propsPool = new Map()
  const eventPool = new Map()
  const allDOM = dom.getElementsByTagName('*')
  const { vIf, vShow } = propsStatus
  const { vClick } = eventStatus

  let domNode

  for (let i = 0; i < allDOM.length; i++) {
    domNode = allDOM[i]

    const vIfName = domNode.getAttribute(vIf)
    const vShowName = domNode.getAttribute(vShow)
    const vClickEventName = domNode.getAttribute(`@${vClick}`)

    if (vIfName) {
      propsPool.set(domNode, {
        type: vIf,
        prop: vIfName
      })
      domNode.removeAttribute(vIf)
    } else if (vShowName) {
      propsPool.set(domNode, {
        type: vShow,
        prop: vShowName
      })
      domNode.removeAttribute(vShow)
    }

    if (vClickEventName) {
      eventPool.set(domNode, {
        type: vClick,
        handle: methods[vClickEventName]
      })
      domNode.removeAttribute(`@${vClick}`)
    }
  }

  return {
    propsPool,
    eventPool
  }
}